home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_19119.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  22 lines

  1. -- card: 19119 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10.     Person  *person;
  11.  
  12.     person = new(Student);
  13.  
  14. The sole change to the main() function is the use of new() to create a Student object instead of a Person object.  Notice that person is still declared as a pointer to a Person object.  It is legal to assign a pointer of one class to a pointer declared to have another class, as long as the latter class is an ancestor of the former.
  15.  
  16. When a set or print message is sent to the object pointed to by person, TC first determines the class of this object and invokes the appropriate method.  In this case, it is the set() or print() method of the Student class.
  17.  
  18. Later we will declare an array of Person pointers, assign objects of various derived classes to these pointers, and make use of this polymorphism property to pass the same messages to each of the different objects.
  19.  
  20. -- part contents for background part 7
  21. ----- text -----
  22. 47